<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
}
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".detail").hide();
	$(".view").toggle(function(){
		$(this).parent().parent().next().show();
	},function(){
		$(this).parent().parent().next().hide();
	});
	$(".more_click").mouseover(function(){
		$(this).next().show();
	}).mouseout(function(){
		$(this).next().hide();
	});
	$(".more_content").mouseover(function(){
		$(this).show();
	}).mouseout(function(){
		$(this).hide();
	});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#multi_delete_btn").click(function(){
		var ids = get_check();
		if (! ids)
		{
			alert("请选择废弃单！");
			return false;
		}
		if (confirm("确定彻底删除废弃单？"))
		{
			window.location.href="<?=url('Sales::Order/Delete')?>&id=" + ids;
		}
	});
});
</script>
<style>
.more_content {
	position: absolute;
	top: 2px;
	left: 25px;
	width: 50px;
	background-color: #eeeeee;
	z-index: 100;
	display: none;
	border: 1px solid;
}
</style>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th width="50">销售日期</th>
	<td>
		<input type="text" name="begin_sales_time" class="datepicker" value="<?=isset($_GET['begin_sales_time']) ? $_GET['begin_sales_time'] : ''?>" /> to
		<input type="text" name="end_sales_time" class="datepicker" value="<?=isset($_GET['end_sales_time']) ? $_GET['end_sales_time'] : ''?>" />
	</td>
	<th>网站：</th>
	<td>
		<select id="shop_id" name="shop_id">
			<option value="">请选择..</option>
			<?foreach ($shop as $k => $sh):?>
			<optgroup label="<?=$k?>">
			<?foreach ($sh as $s):?>
			<option value="<?=$s['id']?>" <?if(isset($_GET['shop_id']) && $_GET['shop_id'] == $s['id']) echo "selected='selected'";?>><?=$s['name']?></option>
			<?endforeach;?>
			</optgroup>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>本地单号</th>
	<td><input type="text" name="number" value="<?=isset($_GET['number']) ? $_GET['number'] : ''?>" /></td>
	<th>网站单号</th>
	<td><input type="text" name="shop_order_number" value="<?=isset($_GET['shop_order_number']) ? $_GET['shop_order_number'] : ''?>" /></td>
</tr>
<tr>
	<th>买家全名</th>
	<td><input type="text" name="fullname" value="<?=isset($_GET['fullname']) ? $_GET['fullname'] : ''?>" /></td>
	<th>买家邮箱</th>
	<td><input type="text" name="email" value="<?=isset($_GET['email']) ? $_GET['email'] : ''?>" /></td>
</tr>
<tr>
	<th>买家ID</th>
	<td><input type="text" name="shop_buyer_id" value="<?=isset($_GET['shop_buyer_id']) ? $_GET['shop_buyer_id'] : ''?>"/></td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>

<table width="98%" class="list_table" id="list">
	<tr>
		<th width="30"></th>
		<th width="200">网站/店铺</th>
		<th width="100">本地单号</th>
		<th width="70">网站单号</th>
		<th width="100">买家姓名</th>
		<th width="150">销售日期</th>
		<th width="270">原因</th>
		<th width="80">操作</th>
	</tr>
	<?foreach ($sales_order as $so):?>
	<tr>
		<td><input type="checkbox" value="<?=$so['id']?>" /></td>
		<td><?=$so['shop_name']?></td>
		<td><?=$so['number']?></td>
		<td><?=$so['shop_order_number']?></td>
		<td><?=$so['fullname']?></td>
		<td><?=$so['sales_time']?></td>
		<td><?=$so['trash_reason']?></td>
		<td>
			<a class="view" href="javascript:void(0);">查看</a>
			<div style="float: right; position: relative;">
				<a class="more_click">更多&or;</a>
				<div class="more_content">
				<?if ($so['handle_status'] == Q::ini('custom_flag/sales_order_handle_status/new/value') || $so['handle_status'] == Q::ini('custom_flag/sales_order_handle_status/sales_hold/value')):?>
				<a href="<?=url('Sales::Order/Delete', array('id'=>$so['id']))?>" onclick="if(!confirm('确定删除？')) return false;">彻底删除</a>
				<?endif;?>
				<a href="<?=url('Sales::Order/TrashReturn', array('id'=>$so['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>">恢复</a>
				</div>
			</div>
		</td>
	</tr>
	<tr class="detail" style="display: none;">
		<td colspan="25">
			<table width="100%" class="list_table">
				<tr>
					<th width="15%">仓库</th>
					<td width="35%"><?=$so['warehouse_name']?></td>
					<th width="15%">制单人</th>
					<td width="35%"><?=$so['make_user_name']?></td>
				</tr>
				<tr>
					<th width="15%">发货类型</th>
					<td width="35%">
						<?=Helper_BSS_Normal::getIniOne('sales_order_send_method', 'value', $so['send_method'], 'name')?>
						<?=Helper_BSS_Normal::getIniOne('sales_order_resend_reason', 'value', $so['resend_reason'], 'name') ? '('.Helper_BSS_Normal::getIniOne('sales_order_resend_reason', 'value', $so['resend_reason'], 'name').')' : ''?>
					</td>
					<th>支付方式</th>
					<td><?=Helper_BSS_Normal::getIniOne('sales_order_payment_method', 'value', $so['payment_method'], 'name')?></td>
				</tr>
				<tr>
					<th>邮寄方式</th>
					<td><?=$so['shipping_method_name']?></td>
					<th>交易号</th>
					<td><?=$so['transaction_id']?></td>
				</tr>
				<tr>
					<th>买家姓名</th>
					<td><?=$so['fullname']?></td>
					<th>买家Email</th>
					<td><?=$so['email']?></td>
				</tr>
				<tr>
					<th>买家电话</th>
					<td><?=$so['phone']?></td>
					<th>收货地址1</th>
					<td><?=$so['street1']?></td>
				</tr>
				<tr>
					<th>收货地址2</th>
					<td><?=$so['street2']?></td>
					<th>城市</th>
					<td><?=$so['city']?></td>
				</tr>
				<tr>
					<th>州/省</th>
					<td><?=$so['state']?></td>
					<th>邮政编码</th>
					<td><?=$so['zip']?></td>
				</tr>
				<tr>
					<th>国家</th>
					<td><?=$so['country']?></td>
					<th>国家(中文)</th>
					<td><?=$so['country_cn']?></td>
				</tr>
				<tr>
					<th>收取运费</th>
					<td><?=$so['currency_symbol']?><?=sprintf('%.2f', $so['shipping_fee'])?></td>
					<th>折扣</th>
					<td><?=$so['currency_symbol']?><?=sprintf('%.2f', $so['discount'])?></td>
				</tr>
				<tr>
					<th>包裹重量</th>
					<td><?=sprintf('%.2f', $so['weight'])?>g</td>
					<th>发货物流费用</th>
					<td><?=$so['postage_currency_symbol']?><?=sprintf('%.2f', $so['postage'])?></td>
				</tr>
				<?if ($so['address_notes']):?>
				<tr>
					<th>地址备注</th>
					<td align="left" colspan="3"><?=$so['address_notes']?></td>
				</tr>
				<?endif;?>
				<?if ($so['order_notes']):?>
				<tr>
					<th>订单备注</th>
					<td align="left" colspan="3">
					<?foreach ($so['order_notes'] as $son):?>
					<p><?=$son['notes_name']?>(<?=$son['add_time']?>):<?=$son['notes']?></p>
					<?endforeach;?>
					</td>
				</tr>
				<?endif;?>
				<?if ($so['sales_notes'] || $so['warehouse_notes']):?>
				<tr>
					<th>消息备注</th>
					<td align="left" colspan="3">
					<?foreach ($so['sales_notes'] as $ssn):?>
					<p><?=$ssn['notes_name']?>(<?=$ssn['add_time']?>):<?=$ssn['notes']?></p>
					<?endforeach;?>
					<?foreach ($so['warehouse_notes'] as $ssn):?>
					<p><?=$ssn['notes_name']?>(<?=$ssn['add_time']?>):<?=$ssn['notes']?></p>
					<?endforeach;?>
					</td>
				</tr>
				<?endif;?>
				<?if ($so['customer_notes']):?>
				<tr>
					<th>客人备注</th>
					<td align="left" colspan="3">
					<?foreach($so['customer_notes'] as $scn):?>
					<p><?=$scn['notes']?></p>
					<?endforeach;?>
					</td>
				</tr>
				<?endif;?>
				<?if (isset($so['sales_refund']) && $so['has_sales_refund']):?>
				<tr>
					<th>退款信息</th>
					<td align="left" colspan="3">
					<?foreach ($so['sales_refund'] as $ssr):?>
					<p><?=$ssr['refund_account']?>/<?=Helper_BSS_Normal::getIniOne('sales_order_payment_method', 'value', $ssr['refund_method'], 'name')?>(<?=$so['currency_symbol']?><?=$ssr['refund_amount']*$ssr['type']?>):<?=Helper_BSS_Normal::getIniOne('sales_refund_reason', 'value', $ssr['reason'], 'name')?></p>
					<?endforeach;?>
					</td>
				</tr>
				<?endif;?>
			</table>
			<div align="left"><strong>销售订单产品信息</strong></div>
			<table width="100%" class="list_table">
				<tr>
					<th>产品编号</th>
					<th>单价</th>
					<th>数量</th>
					<th>金额</th>
					<th>可用库存</th>
					<th>ShopItemId</th>
					<th>ShopTransactionId</th>
				</tr>
				<?$total_quantity = 0;?>
				<?$total_amount = 0;?>
				<?foreach ($so['item'] as $soi):?>
				<?$item_price = $soi['sales_price'];?>
				<?$total_quantity += $soi['quantity']?>
				<tr>
					<td>
						<?=$soi['number']?>
						<?if ($soi['pic_url']):?>
							<?$pretty_photo_number = 0;?>
							<?foreach ($soi['pic_url'] as $soip):?>
							<a rel="pretty_photo[<?=$soi['id']?>]" href="<?=$soip?>"><?if(!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
							<?$pretty_photo_number = 1;?>
							<?endforeach;?>
						<?endif;?>
					</td>
					<td>
						<?=$so['currency_symbol']?><?=sprintf('%.2f',$soi['sales_price'])?>
						<?foreach ($soi['attr'] as $soia):?>
						<?if ($soia['price'] != 0):?>
						<p><?=$soia['prefix']?><?=$so['currency_symbol']?><?=sprintf('%.2f',$soia['price'])?></p>
							<?if ($soia['prefix'] == '+'):?><?$item_price += $soia['price'];?><?endif;?>
							<?if ($soia['prefix'] == '-'):?><?$item_price -= $soia['price'];?><?endif;?>
						<?endif;?>
						<?endforeach;?>
						<?$item_amount = $item_price * $soi['quantity'];?>
						<?$total_amount += $item_amount;?>
					</td>
					<td><?=$soi['quantity']?></td>
					<td><?=$so['currency_symbol']?><?=sprintf('%.2f',$item_amount)?></td>
					<td></td>
					<td><?=$soi['shop_item_id']?></td>
					<td><?=$soi['shop_transaction_id']?></td>
				</tr>
				<?endforeach;?>
				<tr>
					<td colspan="2">小计</td>
					<td><?=$total_quantity?></td>
					<td><?=$so['currency_symbol']?><?=sprintf('%.2f', $total_amount);?></td>
					<td colspan="4"></td>
				</tr>
				<tr>
					<td colspan="3">总计</td>
					<td><?=$so['currency_symbol']?><?=sprintf('%.2f',$so['amount'])?></td>
					<td colspan="4"></td>
				</tr>
			</table>
		</td>
	</tr>
	<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<td><label><input type="checkbox" id="check_all" /> 全选</label></td>
	<td><input type="button" class="button" id="multi_delete_btn" value="批量彻底删除" /></td>
</tr>
</table>
<?php $this->_endblock();?>